home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / WASTE 1.2 Distribution / WASTE 1.2 / WESelectors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-18  |  5.0 KB  |  164 lines  |  [TEXT/CWIE]

  1. /*
  2.  *    WESelectors.c
  3.  *
  4.  *    WASTE PROJECT
  5.  *  Routines for manipulating selector lookup tables
  6.  *
  7.  *  Copyright (c) 1993-1996 Marco Piovanelli
  8.  *    All Rights Reserved
  9.  *
  10.  *  C port by Dan Crevier
  11.  *
  12.  */
  13.  
  14.  
  15. #include "WASTEIntf.h"
  16.  
  17. // MPW can't handle FIELD_DESC stuff (duh!)
  18.  
  19. #ifdef applec
  20.  
  21. // this is **ugly** and will break if we change the declaration of WERec
  22.  
  23. WELookupTable _weMainSelectorTable[] = {
  24. { weRefCon,             0x0074, 0x0004 },
  25. { wePort,                0x0000, 0x0004 },
  26. { weText,                0x0004, 0x0004 },
  27. { weCharToPixelHook,    0x00B4, 0x0004 },
  28. { weCharByteHook,        0x00C0, 0x0004 },
  29. { weCharTypeHook,        0x00C4, 0x0004 },
  30. { weClickLoop,            0x0094, 0x0004 },
  31. { weCurrentDrag,        0x0084, 0x0004 },
  32. { weDrawTextHook,        0x00AC, 0x0004 },
  33. { weHiliteDropAreaHook, 0x00A8, 0x0004 },
  34. { weLineBreakHook,        0x00B8, 0x0004 },
  35. { weLineArray,            0x0008, 0x0004 },
  36. { wePixelToCharHook,    0x00B0, 0x0004 },
  37. { weTSMPostUpdate,        0x00A0, 0x0004 },
  38. { weTSMPreUpdate,        0x009C, 0x0004 },
  39. { weRunArray,            0x0010, 0x0004 },
  40. { weScrollProc,            0x0098, 0x0004 },
  41. { weStyleTable,            0x000C, 0x0004 },
  42. { weTSMDocumentID,        0x0078, 0x0004 },
  43. { weWordBreakHook,        0x00BC, 0x0004 },
  44. { weTranslateDragHook,    0x00A4, 0x0004 },
  45. #if WASTE_IC_SUPPORT
  46. { weURLHint,            0x00DC, 0x0004 },
  47. #endif
  48. { 0,                     0, 0 }};
  49.  
  50. #if WASTE_OBJECTS
  51.  
  52. WELookupTable _weObjectHandlerSelectorTable[] = {
  53. { weClickHandler,        0x0010, 0x0004 },
  54. { weDrawHandler,        0x000C, 0x0004 },
  55. { weDisposeHandler,        0x0008, 0x0004 },
  56. { weNewHandler,            0x0004, 0x0004 },
  57. { weStreamHandler,      0x0014, 0x0004 },
  58. { weRefCon,             0x0018, 0x0004 },
  59. { 0,                     0, 0 }};
  60.  
  61. #endif  // WASTE_OBJECTS
  62.  
  63. #else
  64.  
  65. // proper way of defining selector tables
  66.  
  67. #define FIELD_OFFSET(FIELD, STRUCT)        (SInt16) &((STRUCT *) 0L)->FIELD
  68. #define FIELD_SIZE(FIELD, STRUCT)        (SInt16) sizeof(((STRUCT *) 0L)->FIELD)
  69. #define FIELD_DESC(FIELD, STRUCT)        { FIELD_OFFSET(FIELD, STRUCT), FIELD_SIZE(FIELD, STRUCT) }
  70.  
  71. WELookupTable _weMainSelectorTable[] = {
  72. { weRefCon,             FIELD_DESC(refCon,                WERec) },
  73. { wePort,                FIELD_DESC(port,                  WERec) },
  74. { weText,                FIELD_DESC(hText,                 WERec) },
  75. { weCharToPixelHook,    FIELD_DESC(charToPixelHook,       WERec) },
  76. { weCharByteHook,        FIELD_DESC(charByteHook,          WERec) },
  77. { weCharTypeHook,        FIELD_DESC(charTypeHook,          WERec) },
  78. { weClickLoop,            FIELD_DESC(clickLoop,             WERec) },
  79. { weCurrentDrag,        FIELD_DESC(currentDrag,           WERec) },
  80. { weDrawTextHook,        FIELD_DESC(drawTextHook,          WERec) },
  81. { weHiliteDropAreaHook,    FIELD_DESC(hiliteDropAreaHook,    WERec) },
  82. { weLineBreakHook,        FIELD_DESC(lineBreakHook,         WERec) },
  83. { weLineArray,            FIELD_DESC(hLines,                WERec) },
  84. { wePixelToCharHook,    FIELD_DESC(pixelToCharHook,       WERec) },
  85. { weTSMPostUpdate,        FIELD_DESC(tsmPostUpdate,         WERec) },
  86. { weTSMPreUpdate,        FIELD_DESC(tsmPreUpdate,          WERec) },
  87. { weRunArray,            FIELD_DESC(hRuns,                 WERec) },
  88. { weScrollProc,            FIELD_DESC(scrollProc,            WERec) },
  89. { weStyleTable,            FIELD_DESC(hStyles,               WERec) },
  90. { weTSMDocumentID,        FIELD_DESC(tsmReference,          WERec) },
  91. { weWordBreakHook,        FIELD_DESC(wordBreakHook,         WERec) },
  92. { weTranslateDragHook,    FIELD_DESC(translateDragHook,     WERec) },
  93. #if WASTE_IC_SUPPORT
  94. { weURLHint,            FIELD_DESC(hURLHint,              WERec) },
  95. #endif
  96. { 0,                     0, 0 }};
  97.  
  98. #if WASTE_OBJECTS
  99.  
  100. WELookupTable _weObjectHandlerSelectorTable[] = {
  101. { weClickHandler,        FIELD_DESC(clickHandler,      WEOHTableElement) },
  102. { weDrawHandler,        FIELD_DESC(drawHandler,       WEOHTableElement) },
  103. { weDisposeHandler,        FIELD_DESC(freeHandler,       WEOHTableElement) },
  104. { weNewHandler,            FIELD_DESC(newHandler,        WEOHTableElement) },
  105. { weStreamHandler,      FIELD_DESC(streamHandler,     WEOHTableElement) },
  106. { weRefCon,             FIELD_DESC(refCon,            WEOHTableElement) },
  107. { 0,                     0, 0 }};
  108.  
  109. #endif    // WASTE_OBJECTS
  110.  
  111. #endif    // !applec
  112.  
  113. pascal void _WELookupSelector(const WELookupTable *table, WESelector selector, WEFieldDescriptor *desc)
  114. {
  115.     for ( ; table->selector != selector ; table++ )
  116.         if ( * (SInt32 *) &(table->desc) == 0L )
  117.             break;
  118.  
  119.     *desc = table->desc;
  120. }
  121.  
  122. pascal OSErr _WEGetField(const WELookupTable *table, WESelector selector, SInt32 *info, void *structure)
  123. {
  124.     WEFieldDescriptor desc;
  125.  
  126.     _WELookupSelector(table, selector, &desc);
  127.  
  128.     if (desc.fLength == 0)
  129.         return weUndefinedSelectorErr;
  130.  
  131.     *info = * (SInt32 *) ((SInt32) structure + desc.fOffset);
  132.     return noErr;
  133. }
  134.  
  135. pascal OSErr _WESetField(const WELookupTable *table, WESelector selector, SInt32 *info, void *structure)
  136. {
  137.     WEFieldDescriptor desc;
  138.  
  139.     _WELookupSelector(table, selector, &desc);
  140.  
  141.     if (desc.fLength == 0)
  142.         return weUndefinedSelectorErr;
  143.  
  144.     * (SInt32 *) ((SInt32) structure + desc.fOffset) = *info;
  145.     return noErr;
  146. }
  147.  
  148. pascal OSErr WEGetInfo(WESelector selector, void *info, WEHandle hWE)
  149. {
  150.     return _WEGetField(_weMainSelectorTable, selector, (SInt32 *) info, *hWE);
  151. }
  152.  
  153. pascal OSErr WESetInfo(WESelector selector, const void *info, WEHandle hWE)
  154. {
  155.     OSErr err;
  156.  
  157.     err = _WESetField(_weMainSelectorTable, selector, (SInt32 *) info, *hWE);
  158.  
  159.     // the hook fields can never be nil, so replace any nil field with the default address
  160.     _WESetStandardHooks(hWE);
  161.  
  162.     return err;
  163. }
  164.